package gy;

public class GY {

	static int gy(String s) {
		if(s == null || s.length() == 0)
			return 0;
		String result = s.substring(0, 1);
        String check = result;
        for(int i = 1; i < s.length(); i++){
        	String newString = s.substring(i, i + 1);
        	int location = check.indexOf(newString);
            if(location == -1)
            	check += newString;
            else{
            	if(check.length() > result.length())
            		result = check;
            	check = check.substring(location + 1) + newString;
            }
        }
        if(check.length() > result.length())
    		result = check;
        return result.length();

    }

	public static void main(String[] args) {
		String s1 = "abcabcbb";
		String s2 = "";
		String s3 = "ppppppppppabcpppppppppp";
		StringBuilder s4 = new StringBuilder();
		for(int i = 0; i < 14999; i++)
			s4.append("p");
		s4.append("b");
		for(int i = 0; i < 15000; i++)
			s4.append("p");
		String s5 = "abcdefghijklmn";
		System.out.println("abcabcbb: " + gy(s1));
		System.out.println(": " + gy(s2));
		System.out.println("ppppppppppabcpppppppppp: " + gy(s3));
		System.out.println("p*14999+b+p*15000: " + gy(s4.toString()));
		System.out.println("abcdefghijklmn: " + gy(s5));
	}

}
